package cse.om.common;

import edu.stanford.nlp.ling.WordTag;
import java.util.ArrayList;
import java.util.List;
import vn.hus.nlp.tagger.VietnameseMaxentTagger;

public class Tagger {

	static VietnameseMaxentTagger tagger;

	static {
		tagger = new VietnameseMaxentTagger();
	}

	public static VietnameseMaxentTagger getTagger() {
		return tagger;
	}

	public static List<WordTag> tagSimpleSentence(String sentence) {
		return tagger.tagText2(sentence);
	}

	public static List<List<WordTag>> tagLine(String line) {
		List<List<WordTag>> result = new ArrayList<>();
		List<WordTag> tagged = tagger.tagText2(line);
		List<WordTag> temp = new ArrayList<>();

		Character ponctuation = null;
		for (WordTag wt : tagged) {
			String word = wt.word();
			if (word.length() <= 0) {
				continue;
			}
			char c = word.charAt(0);
			if (Character.isLetterOrDigit(c)) {
				if (ponctuation != null) {
					switch (ponctuation) {
						case '.':
						case '?':
						case '!':
							result.add(temp);
							temp = new ArrayList<>();
							break;
					}
				}
				ponctuation = null;
			} else {
				ponctuation = c;
			}
			temp.add(wt);
		}
		if (temp.size() > 0)
			result.add(temp);
		return result;
	}
}
